package com.ruoyi.web.controller.cpsp;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.cpsp.domain.RegulationDetail;
import com.ruoyi.cpsp.domain.RegulationDetailAndTimes;
import com.ruoyi.cpsp.service.RegulationDetailAndTimesService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/*
    @create 2022/4/15
*/

@CrossOrigin
@RestController
@RequestMapping("/cpsp/regulationdetailtimes")
public class RegulationDetailAndTimesController {

    @Autowired
    RegulationDetailAndTimesService regulationDetailAndTimesService;

    @ApiOperation("添加记录（Regulation_detail与Regulation_times表同时修改）")
    @PostMapping(value = "/addDetailAndTimes")
    @ResponseBody
    public AjaxResult addForm(@RequestBody RegulationDetailAndTimes regulationDetailAndTimes) throws Exception {
        return AjaxResult.success(regulationDetailAndTimesService.submitForm(regulationDetailAndTimes));
    }

    @PreAuthorize("@ss.hasPermi('system:detail:edit')")
    @ApiOperation("修改记录（Regulation_detail与Regulation_times表同时修改）,id为必选参数")
    @PostMapping(value = "/updateDetailAndTimes")
    @ResponseBody
    public AjaxResult update(@RequestBody RegulationDetailAndTimes regulationDetailAndTimes) throws Exception {
        return AjaxResult.success(regulationDetailAndTimesService.update(regulationDetailAndTimes));
    }

    @ApiOperation("删除记录,id为detail表的id，同时删除Regulation_detail与Regulation_times表里的记录")
    @PostMapping(value = "/deleteDetailAndTimes")
    @ResponseBody
    public AjaxResult delete(@RequestParam Integer id) throws Exception {
        return AjaxResult.success(regulationDetailAndTimesService.delete(id));
    }

    @ApiOperation("联合Regulation_detail以及Regulation_times表查询")
    @PostMapping(value = "/selectDetailAndTimes")
    @ResponseBody
    public AjaxResult selectDetailAndTimes(RegulationDetail regulationDetail){
        return AjaxResult.success(regulationDetailAndTimesService.getTypeAndDetail(regulationDetail));
    }
}
